<%@ page language="java" contentType="text/html; charset=UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles"%>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<!DOCTYPE html>
<html lang="en">
<head>
<script src="resources/js/sha1.js" type="text/javascript"></script>
<script type="text/javascript">
	function formhash(form, oldPassword, newPassword, confirmPassword) {

		oldPassword.value = SHA1(SHA1(oldPassword.value));
		newPassword.value = SHA1(SHA1(newPassword.value));
		confirmPassword.value = SHA1(SHA1(confirmPassword.value));

	}
</script>
	<title><spring:message code="label.changePasswordTitle"/></title>
</head>
<sec:authorize access="hasAnyRole('ROLE_USER', 'ROLE_ADMIN')">
<tiles:insertDefinition name="defaultTemplate">
	<tiles:putAttribute name="body">



		<div class="body">
			<div class="col-md-6 col-xs-6">
				<div class="panel panel-primary">
					<div class="panel-heading">
						<h3 class="panel-title"><spring:message code="label.changePasswordTitle"/></h3>
					</div>

					
				
					
						<c:if test="${not empty mess}">
						<c:if test="${mess ne 'Password changed succsessful!'}">
							<div class="alert alert-warning"><strong>${mess}</strong></div>
						</c:if>
						<c:if test="${mess eq 'Password changed succsessful!'}">
							<div class="alert alert-success"><strong>${mess}</strong></div>
						</c:if>
					</c:if>
					
					
					
					
					<fieldset>
						<form id="changePasswordForm" class="form-horizontal"
							action="processchangepassword" method="POST">

							<div class="row">
								<div class="control-group">
									<label class="control-label col-md-3"><spring:message code="label.oldPassword"/></label>
									<div class="controls">
										<div class="col-md-4">
											<input type="password" class="form-control"
												name="oldPassword" required />
										</div>
									</div>
								</div>
							</div>
							<div class="row">
								<div class="control-group">
									<label class="control-label col-md-3"><spring:message code="label.newPassword"/></label>
									<div class="controls">
										<div class="col-md-4">
											<input type="password" class="form-control"
												name="newPassword" required />
										</div>
									</div>
								</div>
							</div>
							<div class="row">
								<div class="control-group">
									<label class="control-label col-md-3"><spring:message code="label.retypePassword"/></label>
									<div class="controls">
										<div class="col-md-4">
											<input type="password" class="form-control"
												name="confirmPassword" required />
										</div>
									</div>
								</div>
							</div>
							<br>
							<div class="row">
								<div class="control-group">
									<div class="controls">
										<label class="control-label col-md-3"></label>
										<div class="col-md-4" align="right">
											<button type="submit" class="btn btn-primary"
												onclick="formhash(this,this.form.oldPassword,this.form.newPassword,this.form.confirmPassword);"><spring:message code="label.changePasswordTitle"/></button>

										</div>

									</div>
								</div>
							</div>


						</form>
					</fieldset>

				</div>
			</div>
		</div>
		<!--//body  -->



	</tiles:putAttribute>
</tiles:insertDefinition>
</sec:authorize>
<script type="text/javascript">
	$(document).ready(function() 
			{
				$('#changePasswordForm').bootstrapValidator({feedbackIcons : {
												valid : 'glyphicon glyphicon-ok',
												invalid : 'glyphicon glyphicon-remove',
												validating : 'glyphicon glyphicon-refresh'
											},
				fields : {password : {validators : {identical : {field : 'confirmPassword',
															message : 'The password and its confirm are not the same'
														}
													}
												},
												confirmPassword : {
													validators : {
														identical : {
															field : 'password',
															message : 'The password and its confirm are not the same'
									}
								}
							}
						}
					});
		});
	$("#advanceSearch").hide();
</script>